package com.zhou.bjgl.bjgl.util.coder;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.zhou.bjgl.bjgl.util.format.DateFomatUtil;


import java.util.Date;
import java.util.UUID;

public class IdGeneratorUtil {

	final static Snowflake snowflake = IdUtil.createSnowflake(1, 1);

	/**
	 * @info生成主键
	 * @return
	 */
	public static String makeCode(String pre) {
		Date date=new Date();
		return pre+ DateFomatUtil.formatIdPre(date)+getUUID();
	}

	public static String getUUID(){
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if(hashCodeV < 0) {//有可能是负数
            hashCodeV = - hashCodeV;
        }
        return String.format("%010d", hashCodeV);
    }
	public static String getUUIDForId(){

		return UUID.randomUUID().toString().replaceAll("-","");
	}

	/**
	 * 功能描述 生成分布式id
	 *
	 * @param
	 * @return
	 */
	public static String getSnowFlakeID(){
		return snowflake.nextIdStr();
	}


}
